import React from 'react';
import { Button, Form, Select, Input, Row, Col, Modal, Message } from 'antd';
const Option = Select.Option;
const FormItem = Form.Item;

let rebatesRegistModal = React.createClass({
  getInitialState() {
    return {
      data:''
    }
  },
  handleCancel() {
      this.props.hideModal();
      this.handleReset()
  },
  handleSubmit() {
      var selectedrecord = this.props.selectedrecord;
      let param = this.props.form.getFieldsValue();
      param.financeBillId = selectedrecord.financeBillId;
      this.props.form.validateFieldsAndScroll((errors, values) => {
          if (!!errors) {
              console.log('Errors in form!!!');
              return;
          }
          Utils.sendAjax({
              url: '/funder/statistics/rebate',
              data: JSON.stringify(param),
              callback: (result) => {
                  if (result.code === '200') {
                      Modal.success({
                          title: result.message,
                      });
                      this.handleCancel();
                  } else {
                      Message.error(result.message, 10)
                  }
              }
          });
      });
  },
  componentDidMount() {
     var record=this.props.selectedrecord;
      var param={
          tenementId:record.tenementId
      }
      Utils.sendAjax({
          url: '/funder/statistics/rebateDate',
          data: JSON.stringify(param),
          callback: (result) => {
              this.setState({
                  data:result.data
              })
          }
      });
  },
  handleReset() {
      this.props.form.resetFields();
  },
  render() {
      const { getFieldProps } = this.props.form;
      return (
          <Modal title="返款登记" width={400} visible={this.props.visible}onCancel={this.handleCancel} footer="">
              <Form inline form={this.props.form}>
                  <Row gutter={24} className="form-group">
                      <Col sm={24} >
                          <FormItem   label="返款月份"  >
                            
                                 <Input {...getFieldProps('rebateDate', { initialValue:this.state.data,rules: [{ required: true, message: '返款月份不可为空' }] }) }/>
                      
                          </FormItem>
                      </Col>
                  </Row>
                  <Row gutter={24} className="form-group">
                      <Col sm={24}>
                          <FormItem label="返款金额" >
                              <Input {...getFieldProps('rebateAmount', { rules: [{ required: true, message: '返款金额不可为空' }, { validator: Utils.number },] }) }/>
                          </FormItem>
                      </Col>
                  </Row>
                  <Row gutter={24} className="form-group">
                      <Col sm={24}>
                          <FormItem   label="备注">
                              <Input {...getFieldProps('remark', { rules: [{ required: true, message: '备注不可为空' }] }) }/>
                          </FormItem>
                      </Col>
                  </Row>
                  <Row gutter={24}>
                      <Col offset={9} sm={14}>
                          <FormItem >
                              <Button type="primary" onClick={this.handleSubmit}>提交</Button>
                          </FormItem>
                      </Col>
                  </Row>
              </Form>
          </Modal>
      );
  }
});

rebatesRegistModal = Form.create()(rebatesRegistModal);
export default rebatesRegistModal